<template>
  <div class="dialog-wrap">
    <button @click="isShow = true">点我弹个窗</button>

    <teleport to='body'>
      <div
        v-if="isShow"
        class="mask-box"
      >
        <div class="dialog-box">
          <h3>我是一个弹窗</h3>
          <h4>一些内容</h4>
          <h4>一些内容</h4>
          <h4>一些内容</h4>
          <button @click="isShow = false">关闭弹窗</button>
        </div>
      </div>
    </teleport>
  </div>
</template>

<script>
import { ref } from 'vue';

export default {
  name: 'Dialog',
  setup() {
    // 数据
    const isShow = ref(false);

    return {
      isShow
    };
  }
};
</script>

<style lang="scss" scoped>
.dialog-wrap {
  & > button {
    margin-top: 30px;
    cursor: pointer;
  }
}
</style>

<style lang="scss">
.mask-box {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  background-color: rgba(0, 0, 0, 0.5);

  & > .dialog-box {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 300px;
    height: 300px;
    background-color: green;

    & > h3,
    & > h4 {
      margin-bottom: 20px;
    }
    & > button {
      cursor: pointer;
    }
  }
}
</style>
